import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)

const store=new Vuex.Store({
    //存放变量
    state:{
        count:10,
        token:window.sessionStorage.getItem('token'),
        student:[{
             name:'zhangsan',
             age:'17'
        },
        {
            name:'lisi',
            age:'20'
       },
       {
        name:'wangwu',
        age:'19'
   }
    ]
    },
    mutations:{
        addstate(state,number){
            state.count+=number;
            console.log(number)
        },
        addAsyncState(state,number){
            console.log('woshiyigeyibu')
        }
    },
    getters:{
        getStudentByAge(state,getters){
            return function(age){
                return state.student.filter(r=>r.age>age)
            }
           
        }
    },
    actions:{
        addAsyncAction(context,cc){
            console.log(cc)
            return new Promise(resolve=>{
                setTimeout(()=>{
                    context.commit('addAsyncState') 
                    resolve('异步已经执行完了')
                },3000)
            })
           
        }
    }
})

//3导出对象
export  default store